import {createRouter, createWebHashHistory} from 'vue-router'

// import {route, asyncRoutes} from './routes'
// const routes = route

const routes = [    //静态路由
  {
    path:'/',
    name: 'admin',
    component: () => import('@/layout/admin.vue'),
    // 子路由
    children:[
      {
        path: "/",
        name: "Home",
        component: () => import('../pages/home/home.vue'),
        meta:{
          title: '首页'
        }
      },
      {
        path: "/goods/list",
        name: "Goods/list",
        component: () => import('../pages/goods/list.vue'),
        meta:{
          title: '商品管理'
        }
      },
      {
        path: "/category/list",
        name: "Category/list",
        component: () => import('../pages/category/list.vue'),
        meta:{
          title: '分类管理'
        }
      },
      {
        path: "/user/list",
        name: "User/list",
        component: () => import('../pages/user/list.vue'),
        meta:{
          title: '用户列表'
        }
      },
      {
        path: "/goods/list",
        name: "Goods/list",
        component: () => import('../pages/goods/list.vue'),
        meta:{
          title: '商品列表'
        }
      },
      {
        path: "/order/list",
        name: "Order/list",
        component: () => import('../pages/order/list.vue'),
        meta:{
          title: '订单列表'
        }
      },
      {
        path: "/comment/list",
        name: "Comment/list",
        component: () => import('../pages/comment/list.vue'),
        meta:{
          title: '评价列表'
        }
      },
      {
        path: "/image/list",
        name: "Image/list",
        component: () => import('../pages/image/list.vue'),
        meta:{
          title: '图库列表'
        }
      },
      {
        path: "/notice/list",
        name: "Notice/list",
        component: () => import('../pages/notice/list.vue'),
        meta:{
          title: '公告列表'
        }
      },
      {
        path: "/setting/base",
        name: "Setting/base",
        component: () => import('../pages/setting/base.vue'),
        meta:{
          title: '配置列表'
        }
      },
      {
        path: "/coupon/list",
        name: "Coupon/list",
        component: () => import('../pages/coupon/list.vue'),
        meta:{
          title: '优惠券列表'
        }
      },
      {
        path: "/manager/list",
        name: "Manager/list",
        component: () => import('../pages/manager/list.vue'),
        meta:{
          title: '管理员管理'
        }
      },

    ]
  },
  {
    path: '/:pathMatch(.*)*', 
    name: 'NotFound', 
    component: () => import('../pages/other/404.vue'),
    meta:{
      title: '404找不到页面'
    }
  },
  {
    path: '/login', 
    name: 'Login', 
    component: () => import('../pages/login/login.vue'),
    meta:{
      title: '登录'
    }
  },
];


// const asyncRoutes = [    //  动态路由
//   {
//     path: "/",
//     name: "Home",
//     component: () => import('../pages/home/home.vue'),
//     meta:{
//       title: '首页'
//     }
//   },
//   {
//     path: "/goods/list",
//     name: "Goods/list",
//     component: () => import('../pages/goods/list.vue'),
//     meta:{
//       title: '商品管理'
//     }
//   },
//   {
//     path: "/category/list",
//     name: "Category/list",
//     component: () => import('../pages/category/list.vue'),
//     meta:{
//       title: '分类管理'
//     }
//   },
// ]

// const NotFound = {
//   path: '/:pathMatch(.*)*',
//   name: 'NotFound', 
//   component: () => import('../pages/other/404.vue'),
//   meta:{
//     title: '404找不到页面'
//   }
// }

 
export const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

// export default router

//  动态添加路由
// export const addRoutes = (menus) => {
//   // let hasNewRoutes:Boolean = false    // 是否有新路由
//   const findAndAddRoutesByMenus = (arr) => {
//     arr.forEach(e => {
//       let item = asyncRoutes.find(o=>o.path == e.frontpath)
//       if(item && !router.hasRoute(item.path)){
//         router.addRoute("admin",item)
//         // hasNewRoutes = true    //有新路由添加，变为false
//       }
//       if(e.child && e.child.length > 0){
//         findAndAddRoutesByMenus(e.child)
//       }
//     });
//   }
//   findAndAddRoutesByMenus(menus)
//   router.addRoute(NotFound)

//   // console.log('当前路由：getRoutes:',router.getRoutes());    //当前路由
//   // return hasNewRoutes
// }

// export {addRoutes} 